//
//  TVStatementCell.swift
//  StarTimesON
//
//  Created by Toj on 11/15/22.
//  Copyright © 2022 StarTimes. All rights reserved.
//

import UIKit

class TVStatementCell: UITableViewCell {
    
    var statement: TVStatementCellModel? { didSet {
        titleLabel.text = statement?.title
        amountLabel.text = statement?.amountFormat
        amountLabel.sizeToFit()
        dateLabel.text = statement?.createDate
        modeLabel.text = statement?.modeString
    } }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.backgroundColor = .white
        setupMakeAddSubviews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        setupMakeLayoutSubviews()
    }
    
    fileprivate lazy var titleLabel: UILabel = {
        let view = UILabel()
        view.font = UIFont.boldSystemFont(ofSize: 12.f_scale)
        view.textColor = "#333333".to_color
        return view
    }()
    
    fileprivate lazy var amountLabel: UILabel = {
        let view = UILabel()
        view.font = UIFont.boldSystemFont(ofSize: 16.f_scale)
        view.textColor = "#333333".to_color
        view.setContentHuggingPriority(.required, for: .horizontal)
        view.setContentCompressionResistancePriority(.required, for: .horizontal)
        return view
    }()
    
    fileprivate lazy var dateLabel: UILabel = {
        let view = UILabel()
        view.font = UIFont.systemFont(ofSize: 12.f_scale)
        view.textColor = "#999999".to_color
        return view
    }()
    
    fileprivate lazy var modeLabel: UILabel = {
        let view = UILabel()
        view.font = UIFont.systemFont(ofSize: 12.f_scale)
        view.textColor = "#999999".to_color
        return view
    }()
    
    fileprivate lazy var lineView: UIView = {
        let view = UIView()
        view.backgroundColor = "#EEEEEE".to_color
        return view
    }()
}

extension TVStatementCell {
    
    private func setupMakeAddSubviews() {
       contentView.addSubview(titleLabel)
       contentView.addSubview(amountLabel)
       contentView.addSubview(dateLabel)
       contentView.addSubview(modeLabel)
       contentView.addSubview(lineView)
    }
    
    private func setupMakeLayoutSubviews() {
        
        amountLabel.snp.makeConstraints { make in
            make.right.equalTo(contentView)
            make.top.equalTo(14.ui_scale)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(contentView)
            make.centerY.equalTo(amountLabel)
            make.right.equalTo(amountLabel.snp.left)
        }
        
        dateLabel.snp.makeConstraints { make in
            make.top.equalTo(titleLabel.snp.bottom).offset(12.ui_scale)
            make.left.right.equalTo(contentView)
        }
        
        modeLabel.snp.makeConstraints { make in
            make.top.equalTo(dateLabel.snp.bottom).offset(6.ui_scale)
            make.left.right.equalTo(contentView)
        }
        
        lineView.snp.makeConstraints { make in
            make.bottom.left.right.equalTo(contentView)
            make.height.equalTo(1)
        }
    }
}
